//
//  CCRNickViewModel.m
//  Activity
//
//  Created by coco on 15/5/8.
//  Copyright (c) 2015年 coco. All rights reserved.
//

#import "CCRNickViewModel.h"
#import <AVOSCloud/AVOSCloud.h>
#import "CCError.h"
@implementation CCRNickViewModel

- (RACSignal *) setNickName:(NSString *)nickName password:(NSString *) password headImage:(NSString *)path {
  return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//    if (path != nil) {
//      AVFile *head = [AVFile fileWithURL:path];
//      [head saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
//        if (succeeded) {
//          [AVUser currentUser].username = nickName;
//          [AVUser currentUser].password = password;
//          [[AVUser currentUser] setObject:head.name forKey:@"headImage"];
//          [[AVUser currentUser] signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
//            if (succeeded) {
//              [subscriber sendNext:[CCError errorWithCode:0 des:@"成功"]];
//            } else {
//              [subscriber sendNext:[CCError errorWithCode:2 des:@"昵称/密码设置错误"]];
//            }
//          }];
//
//          // 设置头像成功
//        } else {
//          [subscriber sendNext:[CCError errorWithCode:3 des:@"头像设置失败"]];
//        }
//      }];
//    }
    [AVUser currentUser].username = nickName;
    [AVUser currentUser].password = password;
    [[AVUser currentUser] setObject:@"heheh" forKey:@"headImage"];
    [[AVUser currentUser] signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
      if (succeeded) {
        [subscriber sendNext:[CCError errorWithCode:0 des:@"成功"]];
      } else {
        [subscriber sendNext:[CCError errorWithCode:2 des:@"昵称/密码设置错误"]];
      }
    }];

    [subscriber sendCompleted];
    return [RACDisposable disposableWithBlock:^{
    }];
  }];
}
@end
